E) Infinity in C++

Infinity를 클래스(구조체)로 구현하고 연산자에 대한 오버로딩 필요

limits에 std::numeric::limits::infinity()를 사용할 수 있다.
#include <limits>
int inf=numeric_limits<int>::infinity();
infinite.h
#pragma once
#ifndef MATH_INFINITE_H_7DE_6_B_INCLUDED
#define MATH_INFINITE_H_7DE_6_B_INCLUDED
#ifdef __cplusplus
const class{ //this object is const object
//infinite is left value
public:
template<typename T>
bool operator==(T&& type)const{
return false;
}
template<typename T>
bool operator!=(T&& type)const{
return true;
}
template<typename T>
bool operator<(T&& type)const{
return false;
}
template<typename T>
bool operator<=(T&& type)const{
return false;
}
template<typename T>
bool operator>(T&& type)const{
return true;
}
template<typename T>
bool operator>=(T&& type)const{
return true;
}
}infinite = {};
using infinite_t = decltype(infinite);
//infinite is right value
template<typename T>
bool operator==(T type, const infinite_t& i){
return false;
}
template<typename T>
bool operator!=(T type, const infinite_t& i){
return true;
}
template<typename T>
bool operator<(T type, const infinite_t& i){
return true;
}
template<typename T>
bool operator<=(T type, const infinite_t& i){
return true;
}
template<typename T>
bool operator>(T type, const infinite_t& i){
return false;
}
template<typename T>
bool operator>=(T type, const infinite_t& i){
return false;
}
#else
//c language
#include<float.h>
#define infinite DBL_MAX
#endif //__cplusplus
#endif //MATH_INFINITE_H_7DE_6_B_INCLUDED